package com.louis.kitty.admin.controller;

import java.util.List;

import com.louis.kitty.admin.dao.SysDeptMapper;
import com.louis.kitty.admin.model.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.louis.kitty.admin.model.SysDept;
import com.louis.kitty.admin.sevice.SysDeptService;
import com.louis.kitty.core.http.HttpResult;

/**
 * 机构控制器
 * @author Louis
 * @date Oct 29, 2018
 */
@RestController
@RequestMapping("dept")
public class SysDeptController {

	@Autowired
	private SysDeptService sysDeptService;

	@Autowired
	private SysDeptMapper sysDeptMapper;

	@PostMapping(value="/save")
	public HttpResult save(@RequestBody SysDept record) {
		//System.out.printf(record.getCompanyId().toString());
		return HttpResult.ok(sysDeptService.save(record));
	}

	@PostMapping(value="/delete")
	public HttpResult delete(@RequestBody List<SysDept> records) {
		return HttpResult.ok(sysDeptService.delete(records));
	}

	@GetMapping(value="/findTree")
	public HttpResult findTree() {
		return HttpResult.ok(sysDeptService.findTree());
	}

	@GetMapping(value="/findDepts")
	public HttpResult findDepts() {
		return HttpResult.ok(sysDeptService.findDepts());
	}

	@GetMapping(value="/findTreeByCompanyList")
	public HttpResult findTreeByCompanyList(Integer companyId) {
		return HttpResult.ok(sysDeptService.findTreeByCompanyId(companyId));
	}

	@GetMapping(value="/findByCompanyId")
	public HttpResult findByCompanyId(Integer companyId) {
		return HttpResult.ok(sysDeptService.findByCompanyId(companyId));
	}
	@GetMapping(value="/findByCompanyIdList")
	public HttpResult findByCompanyIdList(Integer companyId) {
		return HttpResult.ok(sysDeptService.findByCompanyIdList(companyId));
	}


	@GetMapping(value="/selectByPrimaryKey")
	public HttpResult selectByPrimaryKey(Long deptId) {
		return HttpResult.ok(sysDeptService.findById(deptId));
	}

}
